﻿@inherits LayoutComponentBase
@layout BaseLayout
@namespace ThingsGateway.Razor
@using BootstrapBlazor.Components
@using ThingsGateway.Admin.Application
@using ThingsGateway.Admin.Razor
@using ThingsGateway.Core.Extension
@using ThingsGateway.NewLife.X.Extension
@using ThingsGateway.Razor
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.Extensions.Localization

@using System.ComponentModel
@using System.ComponentModel.DataAnnotations

@inject NavigationManager NavigationManager

<SysSignalR />
<CascadingValue Value="ReloadMenu" Name="ReloadMenu" IsFixed="true">
    <CascadingValue Value="ReloadUser" Name="ReloadUser" IsFixed="true">

        <div class="mainlayout">

            <Layout SideWidth="0" IsPage="true" IsFullSide="true" IsFixedHeader="true"
                    ShowGotoTop="true" ShowCollapseBar="true" Menus="@MenuService.MenuItems"
                    AdditionalAssemblies=NetCoreApp.RazorAssemblies AllowDragTab=true
                    UseTabSet="false" TabDefaultUrl="/">
                <Header>

                    <div class="flex-fill"></div>

                    @* 搜索框 *@
                    <GlobalSearch Menus=@(MenuService.SameLevelMenuItems) />

                    @* 语言选择 *@
                    <div class="d-none d-xl-flex ">
                        <CultureChooser />
                    </div>

                    <Logout ImageUrl="@(AppContext.CurrentUser.Avatar??$"{WebsiteConst.DefaultResourceUrl}images/defaultUser.svg")" ShowUserName=false DisplayName="@UserManager.UserAccount" UserName="@UserManager.UserAccount">
                        <LinkTemplate>
                            @* 切换模块 *@
                            <a @onclick="ChoiceModule"><i class="fas fa-arrow-right-arrow-left me-2" />@Localizer["ChoiceModule"]</a>
                            <a @onclick="@OnUserInfoDialog"><i class="fa-solid fa-suitcase me-2"></i>@Localizer["UserCenter"]</a>
                            <a @onclick="@LogoutAsync"><i class="fa-solid fa-key me-2"></i>@Localizer["Logout"]</a>

                        </LinkTemplate>
                    </Logout>

                    @* 全屏按钮 *@
                    <FullScreenButton class="layout-header-bar d-none d-lg-flex px-2" Icon="fa fa-arrows-alt"
                                      TooltipPlacement=Placement.Bottom TooltipText="@Localizer[nameof(FullScreenButton)]" />

                    @if (WebsiteOption.Value.IsShowAbout)
                    {
                        <Button @onclick="ShowAbout" class="layout-header-bar d-none d-lg-flex px-2" Icon="fa fa-info" Color="Color.None" TooltipText="@Localizer[nameof(About)]" />
                    }
                    @* 版本号 *@
                    <div class="px-1 navbar-header-text d-none d-lg-block">@_versionString</div>

                    @* 主题切换 *@
                    @* <ThemeToggle /> *@
                    <ThemeProvider class="layout-header-bar d-none d-lg-flex px-0"></ThemeProvider>

                </Header>
                <Side>
                    <div class="layout-banner">
                        <span class="avatar">
                            @WebsiteOption.Value.Title?.GetNameLen2()
                        </span>

                        <div class="layout-title d-flex align-items-center justify-content-center">
                            <span>@WebsiteOption.Value.Title</span>
                        </div>
                    </div>
                </Side>
                <Main>
                    <Tab ClickTabToNavigation="true" ShowExtendButtons="false" ShowClose="true" AllowDrag=true
                         AdditionalAssemblies="@NetCoreApp.RazorAssemblies" Menus="@MenuService.MenuItems"
                         DefaultUrl=@("/") Body=@(Body!) OnCloseTabItemAsync=@((a)=>
                         {
                           return  Task.FromResult(!(a.Url=="/"||a.Url.IsNullOrEmpty()));
                         })>
                    </Tab>

                </Main>
                <NotAuthorized>
                    <Redirect Url="/Account/Login"/>
                </NotAuthorized>
            </Layout>

            @{
                #if !Admin
                {
            if (AppContext.IsHasButtonWithRole(string.Empty, "快捷按钮"))
            {
                <ThingsGateway.Gateway.Razor.QuickActions></ThingsGateway.Gateway.Razor.QuickActions>
            }
                }

                #endif
            }

        </div>

    </CascadingValue>
</CascadingValue>

